package com.fr.report.io.core;

import com.fr.base.FRContext;
import com.fr.base.core.FT;
import com.fr.report.CellElement;
import com.fr.report.DefaultCellElement;
import com.fr.report.FineBook;
import com.fr.report.FloatElement;
import com.fr.report.PageSet;
import com.fr.report.Report;
import com.fr.report.ReportHF;
import com.fr.report.ReportPage;
import com.fr.report.ReportPageAttr;
import com.fr.report.ReportSettings;
import com.fr.report.ResultWorkBook;
import com.fr.report.cellElement.CellPageAttr;
import com.fr.report.core.DynamicValueList;
import com.fr.report.core.ReportUtils;
import com.fr.report.io.ExcelExporter;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class LargeDataExcelExporterReport extends ExcelReport
{
  private static final int MAX_ROW_COUNT = 25000;
  private Report sourceReport;
  private PageSet pageSet;
  private FT pn_area;
  private List floatList = null;
  private ResultWorkBook workbook = null;
  private boolean isPage = true;

  public LargeDataExcelExporterReport(Report paramReport, PageSet paramPageSet, FT paramFT, boolean paramBoolean)
  {
    this.sourceReport = paramReport;
    this.pageSet = paramPageSet;
    this.pn_area = paramFT;
    this.isPage = paramBoolean;
    this.columnWidthList = new DynamicValueList(19, 25000);
    this.rowHeightList = new DynamicValueList(19, ExcelExporter.EXCELROWS);
  }

  public int getColumnWidth(int paramInt)
  {
    return this.columnWidthList.get(paramInt);
  }

  public int getRowHeight(int paramInt)
  {
    return this.rowHeightList.get(paramInt);
  }

  public Iterator cellIterator()
  {
    return new PageExcelCellIterator(this, null);
  }

  public Iterator floatIterator()
  {
    return ((this.floatList == null) ? null : this.floatList.iterator());
  }

  public ReportHF getFooter(int paramInt)
  {
    return this.sourceReport.getFooter(paramInt);
  }

  public ReportHF getHeader(int paramInt)
  {
    return this.sourceReport.getHeader(paramInt);
  }

  public ReportPageAttr getReportPageAttr()
  {
    return this.sourceReport.getReportPageAttr();
  }

  public ReportSettings getReportSettings()
  {
    return ReportUtils.getReportSettings(this.sourceReport);
  }

  public ResultWorkBook getResultWorkBook()
  {
    return this.workbook;
  }

  public void setResultWorkBook(ResultWorkBook paramResultWorkBook)
  {
    this.workbook = paramResultWorkBook;
  }

  public FineBook getBook()
  {
    return this.workbook;
  }

  static List access$102(LargeDataExcelExporterReport paramLargeDataExcelExporterReport, List paramList)
  {
    return (paramLargeDataExcelExporterReport.floatList = paramList);
  }

  static FT access$200(LargeDataExcelExporterReport paramLargeDataExcelExporterReport)
  {
    return paramLargeDataExcelExporterReport.pn_area;
  }

  static PageSet access$300(LargeDataExcelExporterReport paramLargeDataExcelExporterReport)
  {
    return paramLargeDataExcelExporterReport.pageSet;
  }

  static List access$100(LargeDataExcelExporterReport paramLargeDataExcelExporterReport)
  {
    return paramLargeDataExcelExporterReport.floatList;
  }

  static boolean access$400(LargeDataExcelExporterReport paramLargeDataExcelExporterReport)
  {
    return paramLargeDataExcelExporterReport.isPage;
  }

  private class PageExcelCellIterator
    implements Iterator
  {
    private CellElement next;
    private Iterator current_it;
    private int current_page_y;
    private int current_page_x;
    private int current_row;
    private int first_y;
    private int maxX;
    private int maxY;
    private Point current_offset;
    private boolean[] x_checklast;
    private List reportPageList;
    private int row_count;
    private int pn;
    private final LargeDataExcelExporterReport this$0;

    private PageExcelCellIterator()
    {
      this.this$0 = paramLargeDataExcelExporterReport;
      this.maxX = 2147483647;
      this.maxY = 2147483647;
      this.x_checklast = new boolean[1];
      this.reportPageList = null;
      LargeDataExcelExporterReport.access$102(paramLargeDataExcelExporterReport, new ArrayList());
      this.current_offset = new Point(0, 0);
      this.pn = LargeDataExcelExporterReport.access$200(paramLargeDataExcelExporterReport).from;
      findNext();
      if (this.next == null)
        this.next = new DefaultCellElement(0, 0, "");
    }

    public boolean hasNext()
    {
      return (this.next != null);
    }

    public Object next()
    {
      if (!(hasNext()))
        throw new NoSuchElementException("At last element");
      CellElement localCellElement = this.next;
      findNext();
      return localCellElement;
    }

    private void findNext()
    {
      while ((this.reportPageList != null) || (this.maxY == 2147483647))
      {
        if (this.reportPageList == null)
        {
          this.reportPageList = new ArrayList();
          ReportPage localReportPage1 = null;
          while ((localReportPage1 = LargeDataExcelExporterReport.access$300(this.this$0).getPage(this.pn)) != null)
          {
            if (this.reportPageList.size() == 0)
            {
              this.current_page_y = localReportPage1.getXY()[1];
              if (LargeDataExcelExporterReport.access$200(this.this$0).from == this.pn)
              {
                this.row_count += localReportPage1.getRowCount();
                this.first_y = this.current_page_y;
              }
            }
            else if (localReportPage1.getXY()[1] != this.current_page_y)
            {
              if (this.current_page_y == this.first_y)
              {
                this.maxX = this.reportPageList.size();
                this.x_checklast = new boolean[this.maxX];
              }
              this.row_count += localReportPage1.getRowCount();
              if (this.row_count <= 25000)
                break;
              this.maxY = this.current_page_y;
              LargeDataExcelExporterReport.access$200(this.this$0).to = this.pn;
              break;
            }
            this.reportPageList.add(localReportPage1);
            this.pn += 1;
          }
          if (localReportPage1 == null)
          {
            if (this.reportPageList.size() == 0)
              this.maxY = 0;
            else
              this.maxY = this.current_page_y;
            LargeDataExcelExporterReport.access$200(this.this$0).to = (this.pn = -1);
          }
        }
        if (this.reportPageList.size() > 0)
        {
          i = ((ReportPage)this.reportPageList.get(0)).getRowCount();
          while (this.current_row < i)
          {
            while (this.current_page_x < this.reportPageList.size())
            {
              Object localObject;
              ReportPage localReportPage2 = (ReportPage)this.reportPageList.get(this.current_page_x);
              if (this.current_it == null)
              {
                int j;
                this.current_it = localReportPage2.getRow(this.current_row);
                if ((this.current_page_y == this.first_y) && (this.current_row == 0))
                  for (j = 0; j < localReportPage2.getColumnCount(); ++j)
                    this.this$0.columnWidthList.set(this.current_offset.x + j, localReportPage2.getColumnWidth(j));
                if ((this.current_page_x == 0) && (this.current_row == 0))
                  for (j = 0; j < localReportPage2.getRowCount(); ++j)
                    this.this$0.rowHeightList.set(this.current_offset.y + j, localReportPage2.getRowHeight(j));
                if (this.current_row == 0)
                {
                  localObject = localReportPage2.floatIterator();
                  while (((Iterator)localObject).hasNext())
                  {
                    FloatElement localFloatElement = (FloatElement)((Iterator)localObject).next();
                    localFloatElement.setRow(localFloatElement.getRow() + this.current_offset.y);
                    localFloatElement.setColumn(localFloatElement.getColumn() + this.current_offset.x);
                    LargeDataExcelExporterReport.access$100(this.this$0).add(localFloatElement);
                  }
                }
              }
              if (this.current_it.hasNext())
              {
                localObject = (CellElement)this.current_it.next();
                if ((((CellElement)localObject).getRow() + ((CellElement)localObject).getRowSpan() == localReportPage2.getRowCount()) && (((CellElement)localObject).getColumn() + ((CellElement)localObject).getColumnSpan() == localReportPage2.getColumnCount()))
                {
                  if (((CellElement)localObject).getCellPageAttr() != null)
                    try
                    {
                      ((CellElement)localObject).setCellPageAttr((CellPageAttr)((CellElement)localObject).getCellPageAttr().clone());
                    }
                    catch (CloneNotSupportedException localCloneNotSupportedException)
                    {
                      FRContext.getLogger().log(Level.WARNING, localCloneNotSupportedException.getMessage(), localCloneNotSupportedException);
                    }
                  else
                    ((CellElement)localObject).setCellPageAttr(new CellPageAttr());
                  if (LargeDataExcelExporterReport.access$400(this.this$0))
                  {
                    if ((this.current_page_x == this.maxX) && (this.current_page_y == this.maxY))
                      break label804:
                    if (this.current_page_x == this.maxX)
                    {
                      ((CellElement)localObject).getCellPageAttr().setPageAfterRow(true);
                    }
                    else if (this.current_page_y == this.maxY)
                    {
                      ((CellElement)localObject).getCellPageAttr().setPageAfterColumn(true);
                    }
                    else
                    {
                      ((CellElement)localObject).getCellPageAttr().setPageAfterRow(true);
                      ((CellElement)localObject).getCellPageAttr().setPageAfterColumn(true);
                    }
                  }
                  label804: this.x_checklast[this.current_page_x] = true;
                }
                ((CellElement)localObject).setRow(((CellElement)localObject).getRow() + this.current_offset.y);
                ((CellElement)localObject).setColumn(((CellElement)localObject).getColumn() + this.current_offset.x);
                this.next = ((CellElement)localObject);
                return;
              }
              if ((this.current_row == i - 1) && (this.x_checklast[this.current_page_x] == 0))
              {
                localObject = new DefaultCellElement();
                ((CellElement)localObject).setRow(this.current_offset.y + localReportPage2.getRowCount() - 1);
                ((CellElement)localObject).setColumn(this.current_offset.x + localReportPage2.getColumnCount() - 1);
                ((CellElement)localObject).setCellPageAttr(new CellPageAttr());
                if (LargeDataExcelExporterReport.access$400(this.this$0))
                {
                  if ((this.current_page_x == this.maxX) && (this.current_page_y == this.maxY))
                    break label1046:
                  if (this.current_page_x == this.maxX)
                  {
                    ((CellElement)localObject).getCellPageAttr().setPageAfterRow(true);
                  }
                  else if (this.current_page_y == this.maxY)
                  {
                    ((CellElement)localObject).getCellPageAttr().setPageAfterColumn(true);
                  }
                  else
                  {
                    ((CellElement)localObject).getCellPageAttr().setPageAfterRow(true);
                    ((CellElement)localObject).getCellPageAttr().setPageAfterColumn(true);
                  }
                }
                label1046: this.x_checklast[this.current_page_x] = true;
                this.next = ((CellElement)localObject);
                return;
              }
              this.current_it = null;
              this.current_offset.x += localReportPage2.getColumnCount();
              this.current_page_x += 1;
            }
            this.current_page_x = 0;
            this.current_offset.x = 0;
            this.current_row += 1;
          }
        }
        for (int i = 0; i < this.x_checklast.length; ++i)
          this.x_checklast[i] = false;
        this.current_offset.y += this.current_row;
        this.current_row = 0;
        this.reportPageList = null;
      }
      this.next = null;
    }

    public void remove()
    {
      throw new UnsupportedOperationException();
    }

    PageExcelCellIterator(, LargeDataExcelExporterReport.1 param1)
    {
      this(paramLargeDataExcelExporterReport);
    }
  }
}